package basic.JUC;

/**
 * @创建人 MBY381
 * @创建时间 2022/4/13 14:08
 * @描述 暂无
 */
public class DeathLock {
    public static void main(String[] args) throws InterruptedException {
        deathLock();
    }

    public static void deathLock() throws InterruptedException {
        Object o1 = new Object();
        Object o2 = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (o1) {
                try {
                    FirstTrial.printThreadName();
                    System.out.println("开始运行");
                    Thread.sleep(1000);
                    synchronized (o2) {
                        System.out.println("线程1");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized (o2) {
                try {
                    FirstTrial.printThreadName();
                    System.out.println("开始运行");
                    Thread.sleep(1000);
                    synchronized (o1) {
                        System.out.println("线程2");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        Thread.sleep(100);
        t2.start();
    }
}
